package com.sxj.corejava.code07_面向对象.bms;

/**
 * @author 石小俊
 * @date 2025年07月22日 13:42
 */
public class LoanSavingAccount extends SavingAccount implements Loanable {

    // 贷款金额
    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void providerLoan(double money) {
        // 由于此处进行了简化,没有审批流程,默认直接贷款成功
        // 因此,贷款后贷款金额发生变化即可
        loanAmount += money;
        // 贷款的金额会存储到账户余额
        setBalance(getBalance() + money);
    }

    @Override
    public boolean payLoan(double money) {
        // 由于此处属于贷款的储蓄账户
        // 因此,还贷时要求当前账户余额不低于还贷的金额
        // 只有账户余额不低于还贷金额时,才能成功还贷
        if (getBalance() >= money) {
            // 还贷后当前账户余额减少
            setBalance(getBalance() - money);
            // 当前贷款金额减少
            loanAmount -= money;
            return true;
        }
        return false;
    }

    @Override
    public double queryLoan() {
        // 查询当前贷款的金额
        return loanAmount;
    }
}
